//
//  ZCNavView.m
//  03地图定位
//
//  Created by 张聪 on 16/7/22.
//  Copyright © 2016年 张聪. All rights reserved.
//

#import "ZCNavView.h"
#import "Masonry.h"
#import <MapKit/MapKit.h>

@interface ZCNavView()



@end

@implementation ZCNavView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor grayColor];
        //导航
        UIButton *navBtn = [[UIButton alloc] init];
        self.navBtn = navBtn;
        navBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [navBtn setTitle:@"开始导航" forState:UIControlStateNormal];
        navBtn.backgroundColor = [UIColor orangeColor];
        
        [self addSubview:navBtn];
        
        
        //输入框
        UITextField *endTextField = [[UITextField alloc] init];
        self.endTextField = endTextField;
        endTextField.placeholder = @"请输入终点";
        endTextField.font = [UIFont systemFontOfSize:13];
        endTextField.borderStyle = UITextBorderStyleRoundedRect;
        self.endTextField = endTextField;
        [self addSubview:endTextField];

        
        
    }
    
    
    return self;
}


//添加子控件
- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    [self.navBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.trailing.equalTo(self).offset(-20);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
        
    }];
    
    [self.navBtn addTarget:self action:@selector(didNavBtnClicks) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self.endTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.leading.equalTo(self).offset(20);
        make.trailing.equalTo(self.navBtn.mas_leading).offset(-20);
    }];

    
    
    
}

#pragma mark - 事件响应
- (void)didNavBtnClicks {
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"didNavBtnClicks" object:self]; 
}



#pragma mark - 懒加载
- (UITextField *)endTextField {
    
    if (_endTextField == nil) {
        _endTextField = [[UITextField alloc] init];
    }
    
    
    return _endTextField;
}

- (UIButton *)navBtn {
    if (_navBtn == nil) {
        _navBtn = [[UIButton alloc] init];
    }
    
    return _navBtn;
}

- (UILabel *)navLabel {
    if (_navLabel == nil) {
        _navLabel = [[UILabel alloc] init];
    }
    
    return _navLabel;
}

@end
